#include "highlow.h"

void HighLow::h()const
{
    digitalWrite(_pin,HIGH);
}

void HighLow::l()const
{
    digitalWrite(_pin,LOW);
}

void HighLow::t(unsigned int d) const
{
// digitalWrite(_pin,!digitalRead(_pin));
    digitalWrite(_pin,HIGH);
    delay(d);
    digitalWrite(_pin,LOW);
    delay(d);
}
HighLow::HighLow(byte pin)
{
	if(pin>40 || pin<0){
		_pin=2;
	}
	_pin = pin;
	pinMode(_pin,OUTPUT);
}

HighLow::HighLow()
{
	_pin = 2;
	pinMode(_pin,OUTPUT);
}

HighLow::HighLow(byte pin,const char* name):HighLow(pin){
	_name=name;
}

HighLow::HighLow(byte pin,unsigned int duration):HighLow(pin){
	_duration=duration;
}

HighLow::HighLow(byte pin,unsigned int duration,const char* name):HighLow(pin,name){
	_duration=duration;
}

void HighLow::task() {
  while(1){
	t(_duration);
  }
}
void HighLow::doTask(void* _this) {
	static_cast<HighLow*>(_this)->task();
}

void HighLow::startTask() {
  xTaskCreate(this->doTask,_name,2048,this,5,&_taskHandle);
}
void HighLow::endTask() {
	l();
	vTaskDelete(_taskHandle);
}
HighLow::~HighLow()
{
}

/* main.cpp
#include <Arduino.h>
#include "highlow.h"

HighLow hl(23,200),led(2,1000);

void task1(void *pt){
  while(1){
  hl.t(10);
  }
}

void task2(void *pt){
  while(1){
  led.t(1000);
  }
}
void setup() {
  // xTaskCreate(task1,"t1",1024,NULL,1,NULL);
  // xTaskCreate(task2,"t1",1024,NULL,1,NULL);
  hl.startTask();
  led.startTask();
}

void loop() {
  // hl.t(10);
  // led.t(200);
}

*/